<template>
  <van-dropdown-item
    ref="dropdownRef"
    v-bind="$attrs"
    v-on="$listeners"
    :disabled="disabled"
    :title="syncValue || placeholder"
  >
    <VantDataTime
      v-model="syncValue"
      v-bind="{...$props,...$attrs}"
      v-on="$listeners"
      @confirm="confirm"
    ></VantDataTime>
  </van-dropdown-item>
</template>

<script>
import VantDataTime from '../VantDataTime'
export default {
  name: 'VantMenuItemDatetimePicker',
  components: { VantDataTime },
  model: {
    prop: 'value',
    event: 'update:value'
  },
  props: {
    placeholder: {
      type: String,
      default: '请选择'
    },
    type: {
      type: String,
      default: 'date'
    },
    title: {
      type: String,
      default: '选择年月日'
    },
    value: {
      type: String,
      default: ''
    },
    format: {
      type: String,
      default: 'YYYY-MM-DD'
    },
    disabled: {
      type: Boolean,
      default: false
    }
  },
  computed:{
    syncValue:{
      get(){
        return this.value
      },
      set(val){
        this.$emit('update:value',val)
      }
    }
  },
  methods: {
    confirm(){
      this.$refs.dropdownRef.toggle(false)
    }
  }
}
</script>

<style scoped lang="scss">

</style>
